/* 
ajax封装
*/
import axios from 'axios'
import { Message } from 'element-ui'
// 引入local
import local from "@/utils/local";

axios.defaults.baseURL = 'http://127.0.0.1:5000/'


//请求拦截
axios.interceptors.request.use((config) => {
   let token=local.get('t_k')
if(token){
    config.headers.Authorization=token
}



    return config
}), (err) => {
    return Promise.reject(err)
}

// 响应拦截器
axios.interceptors.response.use((response) => {
    let res = response.data
    
    //统一处理
    if(res.code===0){
        Message({
            type:'success',
            message:res.msg
        })
    }
    if(res.code===1||res.code===5001){
        Message.error(res.msg)
    }

    return response
}),(err)=>{
    return Promise.reject(err)
}

export default axios;